home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / Samples / SprocketExamples / GlyphaIV / GlyphaIV Sources / G4Prefs.c < prev    next >
Encoding:
Text File  |  1998-07-14  |  18.7 KB  |  552 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        G4Prefs.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18.     Writers:
  19.  
  20.         (sjb)    Steve Bollinger
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <2>      7/1/98    sjb        Update to CWPro 2
  25. */
  26.  
  27.  
  28. //============================================================================
  29. //----------------------------------------------------------------------------
  30. //                                    Prefs.c
  31. //----------------------------------------------------------------------------
  32. //============================================================================
  33.  
  34. // This is a slick little file that I re-use and re-use.  I wrote it to…
  35. // seemlessly handle System 6 or System 7 with but a single call.  You need…
  36. // to define your own "prefs" struct, but these routines will read and write…
  37. // it to the System folder.
  38.  
  39. #include "G4Externs.h"
  40. #include <Folders.h>                            // Needed for creating a folder.
  41. #include <Gestalt.h>                            // Needed for the Gestalt() call.
  42. #include <Script.h>                                // I can't remember why I needed this.
  43. #include <ToolUtils.h>
  44. #include <TextUtils.h>
  45.  
  46.  
  47. #define    kPrefCreatorType    'zade'                // Change this to reflect your apps creator.
  48. #define    kPrefFileType        'zadP'                // Change this to reflect your prefs type.
  49. #define    kPrefFileName        "\pGlypha Prefs"    // Change this to reflect the name for your prefs.
  50. #define    kDefaultPrefFName    "\pPreferences"        // Name of prefs folder (System 6 only).
  51. #define kPrefsStringsID        160                    // For easy localization.
  52. #define    kPrefsFNameIndex    1                    // This one works with the previous constant.
  53.  
  54.  
  55. Boolean CanUseFindFolder (void);
  56. Boolean GetPrefsFPath (long *, short *);
  57. Boolean CreatePrefsFolder (short *);
  58. Boolean GetPrefsFPath6 (short *);
  59. Boolean WritePrefs (long *, short *, prefsInfo *);
  60. Boolean WritePrefs6 (short *, prefsInfo *);
  61. OSErr ReadPrefs (long *, short *, prefsInfo *);
  62. OSErr ReadPrefs6 (short *, prefsInfo *);
  63. Boolean DeletePrefs (long *, short *);
  64. Boolean DeletePrefs6 (short *);
  65.  
  66.  
  67. //==============================================================  Functions
  68. //--------------------------------------------------------------  CanUseFindFolder
  69.  
  70. // Returns TRUE if we can use the FindFolder() call (a System 7 nicety).
  71.  
  72. Boolean CanUseFindFolder (void)
  73. {
  74.     OSErr        theErr;
  75.     long        theFeature;
  76.     
  77.     if (!DoWeHaveGestalt())        // Darn, have to check for Gestalt() first.
  78.         return(FALSE);            // If no Gestalt(), probably don't have FindFolder().
  79.     
  80.     theErr = Gestalt(gestaltFindFolderAttr, &theFeature);
  81.     if (theErr != noErr)        // Use selector for FindFolder() attribute.
  82.         return(FALSE);
  83.                                 // Now do a bit test specifically for FindFolder().
  84.     if (!BitTst(&theFeature, 31 - gestaltFindFolderPresent))
  85.         return(FALSE);
  86.     else
  87.         return(TRUE);
  88. }
  89.  
  90. //--------------------------------------------------------------  GetPrefsFPath
  91.  
  92. // This function gets the file path to the Preferences folder (for System 7).
  93. // It is called only if we can use FindFolder() (see previous function).
  94.  
  95. Boolean GetPrefsFPath (long *prefDirID, short *systemVolRef)
  96. {
  97.     OSErr        theErr;
  98.                                     // Here's the wiley FindFolder() call.
  99.     theErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder, 
  100.         systemVolRef, prefDirID);    // It returns to us the directory and volume ref.…
  101.     if (theErr != noErr)            // Assuming it worked at all!
  102.         return(FALSE);
  103.     
  104.     return(TRUE);
  105. }
  106.  
  107. //--------------------------------------------------------------  CreatePrefsFolder
  108.  
  109. // This function won't be necessary for System 7, for System 6 though, it creates…
  110. // a folder ("Preferences") in the System folder and returns whether or not it worked.
  111.  
  112. Boolean CreatePrefsFolder (short *systemVolRef)
  113. {
  114.     HFileParam    fileParamBlock;
  115.     Str255        folderName;
  116.     OSErr        theErr;
  117.                                         // Here's our localization.  Rather than…
  118.                                         // hard-code the name "Preferences" in the code…
  119.                                         // we pull up the text from a string resource.
  120.     GetIndString(folderName, kPrefsStringsID, kPrefsFNameIndex);
  121.                                         // Set up a file parameter block.
  122.     fileParamBlock.ioVRefNum = *systemVolRef;
  123.     fileParamBlock.ioDirID = 0;
  124.     fileParamBlock.ioNamePtr = folderName;
  125.     fileParamBlock.ioCompletion = 0L;
  126.                                         // And create a directory (folder).
  127.     theErr = PBDirCreate((HParmBlkPtr)&fileParamBlock, FALSE);
  128.     if (theErr != noErr)                // See that it worked.
  129.     {
  130.         RedAlert("\pPrefs Creation Error");
  131.         return(FALSE);
  132.     }
  133.     return(TRUE);
  134. }
  135.  
  136. //--------------------------------------------------------------  GetPrefsFPath6
  137.  
  138. // If ever there was a case to drop support for System 6 (and require System 7),…
  139. // this is it.  Look at how insidious handling System 6 files can be.  The following…
  140. // function is the "System 6 pedigree" of the above GetPrefsFPath() function.  Note…
  141. // that the GetPrefsFPath() function was ONE CALL!  TWO LINES OF CODE!  The below…
  142. // function is like a page or so.  Anyway, this function is called if Glypha is…
  143. // running under System 6 and essentially returns a volume reference pointing to…
  144. // the preferences folder.
  145.  
  146. Boolean GetPrefsFPath6 (short *systemVolRef)
  147. {
  148.     Str255        folderName, whoCares;
  149.     SysEnvRec    thisWorld;
  150.     CInfoPBRec    catalogInfoPB;
  151.     DirInfo        *directoryInfo = (DirInfo *) &catalogInfoPB;
  152.     HFileInfo    *fileInfo = (HFileInfo *) &catalogInfoPB;
  153.     WDPBRec        workingDirPB;
  154.     long        prefDirID;
  155.     OSErr        theErr;
  156.                                                 // Yokelization.
  157.     GetIndString(folderName, kPrefsStringsID, kPrefsFNameIndex);
  158.                                                 // SysEnvirons() for System folder volRef.
  159.     theErr = SysEnvirons(2, &thisWorld);
  160.     if (theErr != noErr)
  161.         return(FALSE);
  162.                                                 // Okay, here's the volume reference.
  163.     *systemVolRef = thisWorld.sysVRefNum;
  164.     fileInfo->ioVRefNum = *systemVolRef;        // Set up another parameter block.
  165.     fileInfo->ioDirID  = 0;                        // Ignored.
  166.     fileInfo->ioFDirIndex = 0;                    // Irrelevant.
  167.     fileInfo->ioNamePtr = folderName;            // Directory we're looking for.
  168.     fileInfo->ioCompletion = 0L;
  169.     theErr = PBGetCatInfo(&catalogInfoPB, FALSE);
  170.     if (theErr != noErr)                        // Did we fail to find Prefs folder?
  171.     {
  172.         if (theErr != fnfErr)                    // If it WASN'T a file not found error…
  173.         {                                        // then something more sinister is afoot.
  174.             RedAlert("\pPrefs Filepath Error");
  175.         }                                        // Otherwise, need to create prefs folder.
  176.         if (!CreatePrefsFolder(systemVolRef))
  177.             return(FALSE);
  178.                                                 // Again - can we find the prefs folder?
  179.         directoryInfo->ioVRefNum = *systemVolRef;
  180.         directoryInfo->ioFDirIndex = 0;
  181.         directoryInfo->ioNamePtr = folderName;
  182.         theErr = PBGetCatInfo(&catalogInfoPB, FALSE);
  183.         if (theErr != noErr)
  184.         {
  185.             RedAlert("\pPrefs GetCatInfo() Error");
  186.             return(FALSE);
  187.         }
  188.     }
  189.     prefDirID = directoryInfo->ioDrDirID;        // Alright, the dir. ID for prefs folder.
  190.     
  191.     workingDirPB.ioNamePtr = whoCares;            // Now convert working dir. into a "real"…
  192.     workingDirPB.ioVRefNum = *systemVolRef;        // dir. ID so we can get volume number.
  193.     workingDirPB.ioWDIndex = 0;
  194.     workingDirPB.ioWDProcID = 0;
  195.     workingDirPB.ioWDVRefNum = 0;
  196.     workingDirPB.ioCompletion = 0L;
  197.     theErr = PBGetWDInfo(&workingDirPB, FALSE);
  198.     if (theErr != noErr)
  199.     {
  200.         RedAlert("\pPrefs PBGetWDInfo() Error");
  201.     }
  202.                                                 // The volume where directory is located.
  203.     *systemVolRef = workingDirPB.ioWDVRefNum;
  204.     
  205.     workingDirPB.ioNamePtr = whoCares;
  206.     workingDirPB.ioWDDirID = prefDirID;            // Okay, finally, with a directory ID, …
  207.     workingDirPB.ioVRefNum = *systemVolRef;        // and a "hard" volume number…
  208.     workingDirPB.ioWDProcID = 0;                // …
  209.     workingDirPB.ioCompletion = 0L;                // …
  210.     theErr = PBOpenWD(&workingDirPB, FALSE);    // we can create a working directory…
  211.     if (theErr != noErr)                        // control block with which to access…
  212.     {                                            // files in the prefs folder.
  213.         RedAlert("\pPrefs PBOpenWD() Error");
  214.     }
  215.     
  216.     *systemVolRef = workingDirPB.ioVRefNum;
  217.     
  218.     return(TRUE);
  219. }
  220.  
  221. //--------------------------------------------------------------  WritePrefs
  222.  
  223. // This is the System 7 version that handles all the above functions when you…
  224. // want to write out the preferences file.  It is called by SavePrefs() below…
  225. // if we're running under System 7.  It creates an FSSpec record to hold…
  226. // information about where the preferences file is located, creates Glypha's…
  227. // preferences if they are not found, opens the prefences file, writes out…
  228. // the preferences, and the closes the prefs.  Bam, bam, bam.
  229.  
  230. Boolean WritePrefs (long *prefDirID, short *systemVolRef, prefsInfo *thePrefs)
  231. {
  232.     OSErr        theErr;
  233.     short        fileRefNum;
  234.     long        byteCount;
  235.     FSSpec        theSpecs;
  236.     Str255        fileName = kPrefFileName;
  237.                                     // Create FSSpec record from volume ref and dir ID.
  238.     theErr = FSMakeFSSpec(*systemVolRef, *prefDirID, fileName, &theSpecs);
  239.     if (theErr != noErr)            // See if it failed.
  240.     {                                // An fnfErr means file not found error (no prefs).
  241.         if (theErr != fnfErr)        // If that weren't the problem, we're cooked.
  242.             RedAlert("\pPrefs FSMakeFSSpec() Error");
  243.                                     // If it was an fnfErr, create the prefs.
  244.         theErr = FSpCreate(&theSpecs, kPrefCreatorType, kPrefFileType, smSystemScript);
  245.         if (theErr != noErr)        // If we fail to create the prefs, bail.
  246.             RedAlert("\pPrefs FSpCreate() Error");
  247.     }                                // Okay, we either found or made a pref file, open it.
  248.     theErr = FSpOpenDF(&theSpecs, fsRdWrPerm, &fileRefNum);
  249.     if (theErr != noErr)            // As per usual, if we fail, bail.
  250.         RedAlert("\pPrefs FSpOpenDF() Error");
  251.     
  252.     byteCount = sizeof(*thePrefs);    // Get number of bytes to write (your prefs struct).
  253.                                     // And, write out the preferences.
  254.     theErr = FSWrite(fileRefNum, &byteCount, thePrefs);
  255.     if (theErr != noErr)            // Say no more.
  256.         RedAlert("\pPrefs FSWrite() Error");
  257.     
  258.     theErr = FSClose(fileRefNum);    // Close the prefs file.
  259.     if (theErr != noErr)            // Tic, tic.
  260.         RedAlert("\pPrefs FSClose() Error");
  261.     
  262.     return(TRUE);
  263. }
  264.  
  265. //--------------------------------------------------------------  WritePrefs6
  266.  
  267. // This is the System 6 equivalent of the above function.  It handles prefs…
  268. // opening, writing and closing for System 6.
  269.  
  270. Boolean WritePrefs6 (short *systemVolRef, prefsInfo *thePrefs)
  271. {
  272.     OSErr        theErr;
  273.     short        fileRefNum;
  274.     long        byteCount;
  275.     Str255        fileName = kPrefFileName;
  276.                                     // Attempt to open prefs file.
  277.     theErr = FSOpen(fileName, *systemVolRef, &fileRefNum);
  278.     if (theErr != noErr)            // If it failed, maybe the prefs don't exist.
  279.     {                                // An fnfErr means file not found.
  280.         if (theErr != fnfErr)        // See if in fact that WASN'T the reason.
  281.             RedAlert("\pPrefs FSOpen() Error");
  282.                                     // If fnfErr WAS the problem, create the prefs.
  283.         theErr = Create(fileName, *systemVolRef, kPrefCreatorType, kPrefFileType);
  284.         if (theErr != noErr)
  285.             RedAlert("\pPrefs Create() Error");
  286.                                     // Open the prefs file.
  287.         theErr = FSOpen(fileName, *systemVolRef, &fileRefNum);
  288.         if (theErr != noErr)
  289.             RedAlert("\pPrefs FSOpen() Error");
  290.     }
  291.     
  292.     byteCount = sizeof(*thePrefs);    // Get number of bytes to write out.
  293.                                     // Write the prefs out.
  294.     theErr = FSWrite(fileRefNum, &byteCount, thePrefs);
  295.     if (theErr != noErr)
  296.         RedAlert("\pPrefs FSWrite() Error");
  297.                                     // And close the prefs file.
  298.     theErr = FSClose(fileRefNum);
  299.     if (theErr != noErr)
  300.         RedAlert("\pPrefs FSClose() Error");
  301.     
  302.     return(TRUE);
  303. }
  304.  
  305. //--------------------------------------------------------------  SavePrefs
  306.  
  307. // This is the single function called externally to save the preferences.
  308. // You pass it a pointer to your preferences struct and a version number.
  309. // One of the fields in your preferences struct should be a version number…
  310. // (short prefVersion).  This function determines if we're on System 6 or 7…
  311. // and then calls the appropriate routines.  It returns TRUE if all went well…
  312. // or FALSE if any step failed.
  313.  
  314. Boolean SavePrefs (prefsInfo *thePrefs, short versionNow)
  315. {
  316.     long        prefDirID;
  317.     short        systemVolRef;
  318.     Boolean        canUseFSSpecs;
  319.     
  320.     thePrefs->prefVersion = versionNow;            // Set prefVersion to versionNow.
  321.     
  322.     canUseFSSpecs = CanUseFindFolder();            // See if we can use FindFolder().
  323.     if (canUseFSSpecs)                            // If so (System 7) take this route.
  324.     {                                            // Get a path to Preferences folder.
  325.         if (!GetPrefsFPath(&prefDirID, &systemVolRef))
  326.             return(FALSE);
  327.     }
  328.     else                                        // Here's the System 6 version.
  329.     {
  330.         if (!GetPrefsFPath6(&systemVolRef))
  331.             return(FALSE);
  332.     }
  333.     
  334.     if (canUseFSSpecs)                            // Write out the preferences.
  335.     {
  336.         if (!WritePrefs(&prefDirID, &systemVolRef, thePrefs))
  337.             return(FALSE);
  338.     }
  339.     else
  340.     {
  341.         if (!WritePrefs6(&systemVolRef, thePrefs))
  342.             return(FALSE);
  343.     }
  344.     
  345.     return(TRUE);
  346. }
  347.  
  348. //--------------------------------------------------------------  ReadPrefs
  349.  
  350. // This is the System 7 version for reading in the preferences.  It handles…
  351. // opening the prefs, reading in the data to your prefs struct and closing…
  352. // the file.
  353.  
  354. OSErr ReadPrefs (long *prefDirID, short *systemVolRef, prefsInfo *thePrefs)
  355. {
  356.     OSErr        theErr;
  357.     short        fileRefNum;
  358.     long        byteCount;
  359.     FSSpec        theSpecs;
  360.     Str255        fileName = kPrefFileName;
  361.                                     // Get an FSSpec record to the prefs file.
  362.     theErr = FSMakeFSSpec(*systemVolRef, *prefDirID, fileName, &theSpecs);
  363.     if (theErr != noErr)
  364.     {
  365.         if (theErr == fnfErr)        // If it doesn't exist, return - we'll use defaults.
  366.             return(theErr);
  367.         else                        // If some other file error occured, bail.
  368.             RedAlert("\pPrefs FSMakeFSSpec() Error");
  369.     }
  370.                                     // Open the prefs file.
  371.     theErr = FSpOpenDF(&theSpecs, fsRdWrPerm, &fileRefNum);
  372.     if (theErr != noErr)
  373.         RedAlert("\pPrefs FSpOpenDF() Error");
  374.     
  375.     byteCount = sizeof(*thePrefs);    // Determine the number of bytes to read in.
  376.                                     // Read 'em into your prefs struct.
  377.     theErr = FSRead(fileRefNum, &byteCount, thePrefs);
  378.     if (theErr != noErr)            // If there was an error reading the file…
  379.     {                                // close the file and we'll revert to defaults.
  380.         if (theErr == eofErr)
  381.             theErr = FSClose(fileRefNum);
  382.         else                        // If closing failed, bail.
  383.             RedAlert("\pPrefs FSRead() Error");
  384.         return(theErr);
  385.     }
  386.     
  387.     theErr = FSClose(fileRefNum);    // Close the prefs file.
  388.     if (theErr != noErr)
  389.         RedAlert("\pPrefs FSClose() Error");
  390.     
  391.     return(theErr);
  392. }
  393.  
  394. //--------------------------------------------------------------  ReadPrefs6
  395.  
  396. // This is the System 6 version of the above function.  It's basically the same,…
  397. // but doesn't have the luxury of using FSSpec records.
  398.  
  399. OSErr ReadPrefs6 (short *systemVolRef, prefsInfo *thePrefs)
  400. {
  401.     OSErr        theErr;
  402.     short        fileRefNum;
  403.     long        byteCount;
  404.     Str255        fileName = kPrefFileName;
  405.                                 // Attempt to open the prefs file.
  406.     theErr = FSOpen(fileName, *systemVolRef, &fileRefNum);
  407.     if (theErr != noErr)        // Did opening the file fail?
  408.     {
  409.         if (theErr == fnfErr)    // It did - did it fail because it doesn't exist?
  410.             return(theErr);        // Okay, then we'll revert to default settings.
  411.         else                    // Otherwise, we have a more serious problem.
  412.             RedAlert("\pPrefs FSOpen() Error");
  413.     }
  414.                                 // Get number of bytes to read in.
  415.     byteCount = sizeof(*thePrefs);
  416.                                 // Read in the stream of data into prefs struct.
  417.     theErr = FSRead(fileRefNum, &byteCount, thePrefs);
  418.     if (theErr != noErr)        // Did the read fail?
  419.     {                            // Maybe we're reading too much data (new prefs vers).
  420.         if (theErr == eofErr)    // That's okay, we'll use defaults for now.
  421.             theErr = FSClose(fileRefNum);
  422.         else
  423.             RedAlert("\pPrefs FSRead() Error");
  424.         return(theErr);
  425.     }
  426.                                 // Close the prefs file.
  427.     theErr = FSClose(fileRefNum);
  428.     if (theErr != noErr)
  429.         RedAlert("\pPrefs FSClose() Error");
  430.     
  431.     return(theErr);
  432. }
  433.  
  434. //--------------------------------------------------------------  DeletePrefs
  435.  
  436. // It can happen that you introduce a game with only a few preference settings…
  437. // but then later update your game and end up having to add additional settings…
  438. // to be stored in your games preferences.  In this case, the size of the old…
  439. // prefs won't match the size of the new.  Or even if the size is the same, you…
  440. // may have re-ordered the prefs and attempting to load the old prefs will result…
  441. // in garbage.  It is for this reason that I use the "versionNeed" variable and…
  442. // the "prefVersion" field in the prefs struct.  In such a case, the below function…
  443. // will be called to delte the old prefs.  When the prefs are then written out, a…
  444. // new pref file will be created.  This particular function is the System 7 version…
  445. // for deleting the old preferences.
  446.  
  447. Boolean DeletePrefs (long *dirID, short *volRef)
  448. {
  449.     FSSpec        theSpecs;
  450.     Str255        fileName = kPrefFileName;
  451.     OSErr        theErr;
  452.                                             // Create an FSSec record.
  453.     theErr = FSMakeFSSpec(*volRef, *dirID, fileName, &theSpecs);
  454.     if (theErr != noErr)                    // Test to see if it worked.
  455.         return(FALSE);
  456.     else                                    // If it worked…
  457.         theErr = FSpDelete(&theSpecs);        // delete the file.
  458.     
  459.     if (theErr != noErr)
  460.         return(FALSE);
  461.     
  462.     return(TRUE);
  463. }
  464.  
  465. //--------------------------------------------------------------  DeletePrefs6
  466.  
  467. // This is the System 6 version for deleting a preferences file (see above function).
  468.  
  469. Boolean DeletePrefs6 (short *volRef)
  470. {
  471.     Str255        fileName = kPrefFileName;
  472.     OSErr        theErr;
  473.     
  474.     theErr = FSDelete(fileName, *volRef);    // Delete the prefs file.
  475.     
  476.     if (theErr != noErr)
  477.         return(FALSE);
  478.     
  479.     return(TRUE);
  480. }
  481.  
  482. //--------------------------------------------------------------  LoadPrefs
  483.  
  484. // Here is the single call for loading in preferences.  It handles all the…
  485. // above function onvolved with opening and reading in preferences.  It…
  486. // determines whether we are on System 6 or 7 (FSSpecs) and makes the right…
  487. // calls.
  488.  
  489. Boolean LoadPrefs (prefsInfo *thePrefs, short versionNeed)
  490. {
  491.     long        prefDirID;
  492.     OSErr        theErr;
  493.     short        systemVolRef;
  494.     Boolean        canUseFSSpecs, noProblems;
  495.     
  496.     canUseFSSpecs = CanUseFindFolder();    // See if we can use FSSpecs (System 7).
  497.     if (canUseFSSpecs)
  498.     {                                    // Get a path to the prefs file.
  499.         noProblems = GetPrefsFPath(&prefDirID, &systemVolRef);
  500.         if (!noProblems)
  501.             return(FALSE);
  502.     }
  503.     else
  504.     {                                    // Gets path to prefs file (System 6).
  505.         noProblems = GetPrefsFPath6(&systemVolRef);
  506.         if (!noProblems)
  507.             return(FALSE);
  508.     }
  509.     
  510.     if (canUseFSSpecs)
  511.     {                                    // Attempt to read prefs.
  512.         theErr = ReadPrefs(&prefDirID, &systemVolRef, thePrefs);
  513.         if (theErr == eofErr)            // Fail the read?  Maybe an old prefs version.
  514.         {                                // Delete it - we'll create a new one later.
  515.             noProblems = DeletePrefs(&prefDirID, &systemVolRef);
  516.             return(FALSE);                // Meanwhile, we'll use defaults.
  517.         }
  518.         else if (theErr != noErr)
  519.             return(FALSE);
  520.     }
  521.     else
  522.     {                                    // Attempt to read prefs (System 6).
  523.         theErr = ReadPrefs6(&systemVolRef, thePrefs);
  524.         if (theErr == eofErr)            // Fail the read?  Maybe an old prefs version.
  525.         {                                // Delete it - we'll create a new one later.
  526.             noProblems = DeletePrefs6(&systemVolRef);
  527.             return(FALSE);                // Meanwhile, we'll use defaults.
  528.         }
  529.         else if (theErr != noErr)
  530.             return(FALSE);
  531.     }
  532.                                         // Okay, maybe the read worked, but we still…
  533.                                         // need to check the version number to see…
  534.                                         // if it's current.
  535.     if (thePrefs->prefVersion != versionNeed)
  536.     {                                    // We'll delete the file if old version.
  537.         if (canUseFSSpecs)
  538.         {
  539.             noProblems = DeletePrefs(&prefDirID, &systemVolRef);
  540.             return(FALSE);
  541.         }
  542.         else
  543.         {
  544.             noProblems = DeletePrefs6(&systemVolRef);
  545.             return(FALSE);
  546.         }
  547.     }
  548.     
  549.     return(TRUE);
  550. }
  551.  
  552.